<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>注册页面</title>
    <link rel="icon" th:href="@{/favicon.ico}" type="image/ico">
    <meta name="author" content="pxl">
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/materialdesignicons.min.css}" rel="stylesheet">
    <link th:href="@{/css/style.min.css}" rel="stylesheet">

    <style>
        .lyear-wrapper {
            position: relative;
        }
        .lyear-login {
            display: flex !important;
            min-height: 100vh;
            align-items: center !important;
            justify-content: center !important;
        }
        .login-center {
            background: #fff;
            min-width: 38.25rem;
            padding: 2.14286em 3.57143em;
            border-radius: 5px;
            margin: 2.85714em 0;
        }
        .login-header {
            margin-bottom: 1.5rem !important;
        }
        .login-center .has-feedback.feedback-left .form-control {
            padding-left: 38px;
            padding-right: 12px;
        }
        .login-center .has-feedback.feedback-left .form-control-feedback {
            left: 0;
            right: auto;
            width: 38px;
            height: 38px;
            line-height: 38px;
            z-index: 4;
            color: #dcdcdc;
        }
        .login-center .has-feedback.feedback-left.row .form-control-feedback {
            left: 15px;
        }
    </style>
</head>

<body>
<div class="row lyear-wrapper">
    <div class="lyear-login">
        <div class="login-center">
            <div class="login-header text-center">
                <img th:src="@{/images/logo-sidebar.png}" height="55px" width="200px">
            </div>
            <form action="/user/register" method="post">
                <div class="form-group has-feedback feedback-left">
                    <input type="text" placeholder="请输入您的学号" class="form-control" name="userNum" id="username" />
                    <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group has-feedback feedback-left">
                    <input type="text" placeholder="请输入您的名字" class="form-control" name="realName" id="realName" />
                    <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group has-feedback feedback-left">
                    <input type="password" placeholder="请输入密码" class="form-control" id="password" name="password" />
                    <span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group has-feedback feedback-left">
                    <input type="password" placeholder="再次确认密码" class="form-control" id="password1"/>
                    <span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group has-feedback feedback-left">
                    <input type="text" placeholder="请输入您的手机号码" class="form-control" name="phoneNu" id="phoneNu"/>
                    <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group has-feedback feedback-left row">
                    <div class="col-md-8">
                        <input type="text" placeholder="请输入验证码" class="form-control" name="verCode" id="verCode" />
                        <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
                    </div>
                    <div class="col-md-4">
                    <a onclick="sendSms()"><p class="text-justify">发送验证码</p></a>
                </div>
                </div>
                <div class="form-group">
                    <button class="btn  btn-block btn-cyan" type="button" onclick="checkInput()" id="register">注册账号</button>
                </div>
            </form>
            <hr>
        </div>
    </div>
</div>
<script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/js/axios.min.js}"></script>
<script>

    var checkInput=function () {
        var res=true;
        var password=$("#password").val();
        var password1=$("#password1").val()
        alert(password1);
        if(password != password1 || password == ""  || password1 == ""){
            alert("两次密码输入不一致");
            $("#password").val("");
            $("#password1").val("");
            res=false;
        }
        var userNum=$("#username").val();
        if(userNum == undefined || userNum == ""){
            alert("学号不能为空" );
            res=false;
        }else {
            axios.get("/user/register/"+userNum).then(
                function (response) {
                    if(response.data!=""){
                        alert(response.data);
                        $("#username").val("");
                    }
                }
            )
        }
        var realName=$("#realName").val();
        if(realName== undefined || realName == ""){
            alert("名字不能为空");
            res=false;
        }
        var phoneNu=$("#phoneNu").val();
        if(phoneNu == undefined || phoneNu == ""){
            alert("手机号码不能为空");
            res=false;
        }
        var verCode=$("#verCode").val();
        if(verCode == undefined || verCode == "" ){
            alert("验证码不能为空");
            res=false;
        }
        if(res){
            $("#register").attr("type","submit");
        }



    }



    var sendSms=function (){
        var phoneNu=$("#phoneNu").val();
        if(phoneNu != undefined){
            axios.get("/user/sendSms/"+phoneNu).then(
                function (respnse) {
                    alert(JSON.stringify(respnse.data));
                }
            );
        }else {

        }
        //alert(phoneNu);

    }



</script>
<script type="text/javascript">;</script>
</body>
</html>